/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.rafkind.raytracer;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author drafkind
 */
public class Intersection extends VisibleObject {
  private List<VisibleObject> objects;

  public Intersection() {
    objects = new ArrayList<VisibleObject>();
  }

  public List<IntersectionPoint> getIntersectionPoints(Ray ray) {
    List<IntersectionPoint> points = new ArrayList<IntersectionPoint>();
    for (VisibleObject vo : objects) {
      for (IntersectionPoint ip : vo.getIntersectionPoints(ray)) {
        if (isInside(ip.getPoint())) {
          points.add(ip);
        }
      }
    }

    return points;
  }

  public Vector3 getNormalAt(IntersectionPoint where) {
    return where.getTarget().getNormalAt(where);
  }


  @Override public void setTexture(Texture texture) {
    this.texture = texture;

    for (VisibleObject vo : objects) {
      vo.setTexture(texture);
    }
  }

  @Override public boolean isInsideImplementation(Vector3 where) {
    for (VisibleObject vo : objects) {
      if (!vo.isInside(where))
        return false;
    }
    return true;
  }

  public List<VisibleObject> getObjects() {
    return objects;
  }
}
